package com.jhgsys.internal.hazard.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jhgsys.internal.common.entity.QueryRequest;
import com.jhgsys.internal.common.utils.FebsUtil;
import com.jhgsys.internal.hazard.entity.HazardExamineTeamUser;
import com.jhgsys.internal.hazard.mapper.HazardExamineTeamUserMapper;
import com.jhgsys.internal.hazard.service.IHazardExamineTeamUserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 *  Service实现
 *
 * @author zhangwei
 * @date 2024-09-02 11:28:59
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class HazardExamineTeamUserServiceImpl extends ServiceImpl<HazardExamineTeamUserMapper, HazardExamineTeamUser> implements IHazardExamineTeamUserService {

    /**
     * 查询（分页）
     * @author zhangwei
     * @date 2024-09-02 11:28:59
     * @param request QueryRequest
     * @param hazardExamineTeamUser hazardExamineTeamUser
     * @return IPage<HazardExamineTeamUser>
    */
    @Override
    public IPage<HazardExamineTeamUser> findHazardExamineTeamUserPage(QueryRequest request, HazardExamineTeamUser hazardExamineTeamUser) {
        LambdaQueryWrapper<HazardExamineTeamUser> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(HazardExamineTeamUser::getDeletedFlg, 0);
        // TODO 设置查询条件

        Page<HazardExamineTeamUser> page = new Page<>(request.getPageNum(), request.getPageSize());
        FebsUtil.pageWrapper(page, request);
        return this.page(page, queryWrapper);
    }

    /**
     * 查询（所有）
     * @author zhangwei
     * @date 2024-09-02 11:28:59
     * @param hazardExamineTeamUser hazardExamineTeamUser
     * @return List<HazardExamineTeamUser>
     */
    @Override
    public List<HazardExamineTeamUser> findHazardExamineTeamUserList(HazardExamineTeamUser hazardExamineTeamUser) {
	    LambdaQueryWrapper<HazardExamineTeamUser> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(HazardExamineTeamUser::getDeletedFlg, 0);
        if(StringUtils.isNotBlank(hazardExamineTeamUser.getExamineTeamId())){
            queryWrapper.eq(HazardExamineTeamUser::getExamineTeamId,hazardExamineTeamUser.getExamineTeamId() );
        }
		// TODO 设置查询条件
		return this.baseMapper.selectList(queryWrapper);
    }

    /**
    * 根据ID查询
    * @author zhangwei
    * @date 2024-09-02 11:28:59
    * @param id
    * @return HazardExamineTeamUser
    */
    @Override
    public HazardExamineTeamUser findHazardExamineTeamUserById(String id){
        return this.baseMapper.selectById(id);
    }

    /**
     * 新增
     * @author zhangwei
     * @date 2024-09-02 11:28:59
     * @param hazardExamineTeamUser hazardExamineTeamUser
     */
    @Override
    @Transactional
    public void createHazardExamineTeamUser(HazardExamineTeamUser hazardExamineTeamUser) {
        hazardExamineTeamUser.setCreatedTime(new Date());
        this.save(hazardExamineTeamUser);
    }

    /**
     * 修改
     * @author zhangwei
     * @date 2024-09-02 11:28:59
     * @param hazardExamineTeamUser hazardExamineTeamUser
     */
    @Override
    @Transactional
    public void updateHazardExamineTeamUser(HazardExamineTeamUser hazardExamineTeamUser) {
        hazardExamineTeamUser.setUpdatedTime(new Date());
        this.saveOrUpdate(hazardExamineTeamUser);
    }

    /**
     * 逻辑删除
     * @author zhangwei
     * @date 2024-09-02 11:28:59
     * @param hazardExamineTeamUser hazardExamineTeamUser
     * @param hazardExamineTeamUserIds hazardExamineTeamUserIds
     */
    @Override
    @Transactional
    public void deleteHazardExamineTeamUser(HazardExamineTeamUser hazardExamineTeamUser,String hazardExamineTeamUserIds) {
        List<String> list = Arrays.asList(hazardExamineTeamUserIds.split(StringPool.COMMA));
        this.baseMapper.update(hazardExamineTeamUser,new LambdaQueryWrapper<HazardExamineTeamUser>().in(HazardExamineTeamUser::getExamineTeamUserId,list));
	}

    /**
    * 物理删除
    * @author zhangwei
    * @date 2024-09-02 11:28:59
    * @param hazardExamineTeamUserIds hazardExamineTeamUserIds
    */
    @Override
    @Transactional
    public void physicallyDeleteHazardExamineTeamUser(String hazardExamineTeamUserIds) {
        List<String> list = Arrays.asList(hazardExamineTeamUserIds.split(StringPool.COMMA));
        LambdaQueryWrapper<HazardExamineTeamUser> wapper = new LambdaQueryWrapper<>();
        wapper.in(HazardExamineTeamUser::getExamineTeamUserId,list);
        this.remove(wapper);
    }

    /**
     * 根据小组id删除
     * @author admin
     * @date 2024-07-29 15:56:15
     * @param teamIds
     */
    @Override
    @Transactional
    public void deleteByTeamIds(String teamIds) {
        List<String> list = Arrays.asList(teamIds.split(StringPool.COMMA));
        LambdaQueryWrapper<HazardExamineTeamUser> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(HazardExamineTeamUser::getExamineTeamId,list);
        this.remove(wrapper);
    }

    /**
     * 根据teamId查询
     * @author admin
     * @date 2024-07-29 15:56:15
     * @param teamIds
     */
    @Override
    public List<HazardExamineTeamUser> findByTeamIds(String teamIds) {
        List<String> list = Arrays.asList(teamIds.split(StringPool.COMMA));
        LambdaQueryWrapper<HazardExamineTeamUser> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(HazardExamineTeamUser::getExamineTeamId,list);
        return this.list(wrapper);
    }
}
